package com.ltcode.auth.infrastructure.captcha;

import com.google.code.kaptcha.text.impl.DefaultTextCreator;

import java.util.Random;

/**
 * 数学运算验证码文本生成器
 * 
 * @author ltcode
 * @since 2024-01-01
 */
public class KaptchaMathTextCreator extends DefaultTextCreator {

    private static final String[] OPERATORS = {"+", "-", "*"};
    private static final Random RANDOM = new Random();

    @Override
    public String getText() {
        int x = RANDOM.nextInt(10);
        int y = RANDOM.nextInt(10);
        String operator = OPERATORS[RANDOM.nextInt(OPERATORS.length)];
        
        StringBuilder expression = new StringBuilder();
        expression.append(x);
        expression.append(operator);
        expression.append(y);
        expression.append("=?");
        
        return expression.toString();
    }
}
